<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>反转字符串 - 算法详解</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e1e1e;
            border-radius: 12px;
            overflow: hidden;
        }
        .code-header {
            background: #2d2d2d;
            padding: 12px 20px;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        .code-dots {
            display: flex;
            gap: 8px;
        }
        .dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
        }
        .dot-red { background: #ff5f56; }
        .dot-yellow { background: #ffbd2e; }
        .dot-green { background: #27c93f; }
        pre {
            margin: 0;
            padding: 20px;
            overflow-x: auto;
        }
        code {
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            font-size: 14px;
            line-height: 1.6;
            color: #d4d4d4;
        }
        .keyword { color: #c586c0; }
        .type { color: #4ec9b0; }
        .function { color: #dcdcaa; }
        .variable { color: #9cdcfe; }
        .comment { color: #6a9955; }
        .string { color: #ce9178; }
        .number { color: #b5cea8; }
        .operator { color: #d4d4d4; }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.1rem;
            color: #667eea;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .step-indicator {
            position: absolute;
            top: -12px;
            left: -12px;
            width: 40px;
            height: 40px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: bold;
            font-size: 18px;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto">
            <div class="text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 serif-font">反转字符串</h1>
                <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto leading-relaxed">
                    掌握双指针技巧，优雅解决字符串反转问题
                </p>
                <div class="mt-8 flex justify-center gap-6">
                    <div class="bg-white bg-opacity-20 rounded-lg px-6 py-3 backdrop-blur-sm">
                        <i class="fas fa-clock mr-2"></i>
                        <span>时间复杂度 O(n)</span>
                    </div>
                    <div class="bg-white bg-opacity-20 rounded-lg px-6 py-3 backdrop-blur-sm">
                        <i class="fas fa-memory mr-2"></i>
                        <span>空间复杂度 O(1)</span>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-6xl mx-auto px-6 py-12">
        <!-- Problem Description -->
        <section class="mb-16">
            <div class="bg-white rounded-2xl shadow-lg p-8 card-hover">
                <h2 class="text-3xl font-bold mb-6 gradient-text">题目描述</h2>
                <p class="text-lg text-gray-700 leading-relaxed">
                    <span class="drop-cap serif-font">编</span>写一个函数，其作用是将输入的字符串反转并返回。这是一道经典的算法题目，考察对双指针技巧的掌握和对字符串操作的理解。
                </p>
            </div>
        </section>

        <!-- Core Concepts -->
        <section class="mb-16">
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-2xl shadow-lg p-8 card-hover relative">
                    <div class="step-indicator">1</div>
                    <h3 class="text-2xl font-bold mb-4 flex items-center">
                        <i class="fas fa-lightbulb text-yellow-500 mr-3"></i>
                        核心算法
                    </h3>
                    <p class="text-gray-700 mb-4">双指针技巧是解决此类问题的最优方案。通过同时从字符串两端向中间移动，可以在原地完成字符交换，无需额外空间。</p>
                    <div class="bg-purple-50 rounded-lg p-4 mt-4">
                        <p class="text-purple-800 font-medium">
                            <i class="fas fa-info-circle mr-2"></i>
                            双指针技巧广泛应用于数组和字符串问题中
                        </p>
                    </div>
                </div>
                <div class="bg-white rounded-2xl shadow-lg p-8 card-hover relative">
                    <div class="step-indicator">2</div>
                    <h3 class="text-2xl font-bold mb-4 flex items-center">
                        <i class="fas fa-cogs text-blue-500 mr-3"></i>
                        解题思路
                    </h3>
                    <ul class="space-y-3 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mr-3 mt-1"></i>
                            <span>初始化两个指针，分别指向字符串的首尾</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mr-3 mt-1"></i>
                            <span>循环交换两个指针所指向的字符</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mr-3 mt-1"></i>
                            <span>指针相向移动，直到相遇或交错</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>

        <!-- Algorithm Visualization -->
        <section class="mb-16">
            <div class="bg-white rounded-2xl shadow-lg p-8">
                <h2 class="text-3xl font-bold mb-8 gradient-text text-center">算法可视化</h2>
                <div class="mermaid">
                    graph LR
                        A[开始] --> B[初始化 left=0, right=length-1]
                        B --> C{left < right?}
                        C -->|是| D[交换 s[left] 和 s[right]]
                        D --> E[left++, right--]
                        E --> C
                        C -->|否| F[结束]
                        
                        style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                        style F fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                        style D fill:#f59e0b,stroke:#fff,stroke-width:2px,color:#fff
                </div>
            </div>
        </section>

        <!-- Code Implementation -->
        <section class="mb-16">
            <div class="bg-white rounded-2xl shadow-lg p-8">
                <h2 class="text-3xl font-bold mb-8 gradient-text">代码实现</h2>
                <div class="code-block">
                    <div class="code-header">
                        <div class="code-dots">
                            <div class="dot dot-red"></div>
                            <div class="dot dot-yellow"></div>
                            <div class="dot dot-green"></div>
                        </div>
                        <span class="text-gray-400 text-sm">Java</span>
                    </div>
                    <pre><code><span class="keyword">public</span> <span class="type">void</span> <span class="function">reverseString</span>(<span class="type">char</span>[] <span class="variable">s</span>) {
    <span class="comment">// 初始化左指针，指向数组开始位置</span>
    <span class="type">int</span> <span class="variable">left</span> <span class="operator">=</span> <span class="number">0</span>;
    <span class="comment">// 初始化右指针，指向数组末尾位置</span>
    <span class="type">int</span> <span class="variable">right</span> <span class="operator">=</span> <span class="variable">s</span>.<span class="variable">length</span> <span class="operator">-</span> <span class="number">1</span>;
    
    <span class="comment">// 当左指针小于右指针时，继续交换</span>
    <span class="keyword">while</span> (<span class="variable">left</span> <span class="operator">&lt;</span> <span class="variable">right</span>) {
        <span class="comment">// 交换左右指针指向的字符</span>
        <span class="type">char</span> <span class="variable">temp</span> <span class="operator">=</span> <span class="variable">s</span>[<span class="variable">left</span>];
        <span class="variable">s</span>[<span class="variable">left</span>] <span class="operator">=</span> <span class="variable">s</span>[<span class="variable">right</span>];
        <span class="variable">s</span>[<span class="variable">right</span>] <span class="operator">=</span> <span class="variable">temp</span>;
        
        <span class="comment">// 左指针向右移动</span>
        <span class="variable">left</span><span class="operator">++</span>;
        <span class="comment">// 右指针向左移动</span>
        <span class="variable">right</span><span class="operator">--</span>;
    }
}</code></pre>
                </div>
            </div>
        </section>

        <!-- Key Points -->
        <section class="mb-16">
            <div class="bg-gradient-to-r from-purple-100 to-blue-100 rounded-2xl p-8">
                <h2 class="text-3xl font-bold mb-6 text-gray-800">
                    <i class="fas fa-star text-yellow-500 mr-3"></i>
                    关键要点
                </h2>
                <div class="grid md:grid-cols-3 gap-6">
                    <div class="bg-white rounded-lg p-6 text-center card-hover">
                        <i class="fas fa-exchange-alt text-4xl text-purple-600 mb-4"></i>
                        <h4 class="font-bold text-lg mb-2">原地交换</h4>
                        <p class="text-gray-600">不需要额外的数组空间，直接在原数组上进行操作</p>
                    </div>
                    <div class="bg-white rounded-lg p-6 text-center card-hover">
                        <i class="fas fa-arrows-alt-h text-4xl text-blue-600 mb-4"></i>
                        <h4 class="font-bold text-lg mb-2">双指针技巧</h4>
                        <p class="text-gray-600">从两端向中间移动，每次交换一对字符</p>
                    </div>
                    <div class="bg-white rounded-lg p-6 text-center card-hover">
                        <i class="fas fa-tachometer-alt text-4xl text-green-600 mb-4"></i>
                        <h4 class="font-bold text-lg mb-2">最优复杂度</h4>
                        <p class="text-gray-600">时间O(n)，空间O(1)，达到理论最优</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Extended Learning -->
        <section class="mb-16">
            <div class="bg-white rounded-2xl shadow-lg p-8">
                <h2 class="text-3xl font-bold mb-6 gradient-text">扩展学习</h2>
                <div class="space-y-4">
                    <div class="border-l-4 border-purple-500 pl-6 py-2">
                        <h4